<template>
  <div class="wss-container">
    <NewCard title="咨询设置">
      <div class="labelSettings">
        <el-form
          :model="ruleForm"
          :rules="rules"
          ref="ruleForm"
          label-width="200px"
          class="form"
          label-position="left"
        >
          <el-form-item label="回复总时长（小时）" prop="c_effective_hour">
            <el-input maxlength="8" v-model.number="ruleForm.c_effective_hour">
              <template slot="append">专家</template></el-input
            >
          </el-form-item>
          <el-form-item
            label="专家擅长类别上限（个）"
            prop="consult_expert_skilledMax"
          >
            <el-input
              maxlength="8"
              v-model.number="ruleForm.consult_expert_skilledMax"
            >
              <template slot="append">专家</template></el-input
            >
          </el-form-item>

          <el-form-item
            label="专家擅长类别下限（个）"
            prop="consult_expert_skilledMin"
          >
            <el-input
              maxlength="8"
              v-model.number="ruleForm.consult_expert_skilledMin"
            >
              <template slot="append">专家</template></el-input
            >
          </el-form-item>

          <el-form-item label="附件个数上限（个）" prop="c_file_num">
            <el-input maxlength="8" v-model.number="ruleForm.c_file_num">
              <template slot="append">用户</template></el-input
            >
          </el-form-item>
          <el-form-item label="附件单个文件大小上限(M)" prop="c_file_size">
            <el-input maxlength="8" v-model.number="ruleForm.c_file_size">
              <template slot="append">用户</template></el-input
            >
          </el-form-item>
          <el-form-item label="回答字数上限（字）" prop="c_words_max">
            <el-input maxlength="8" v-model.number="ruleForm.c_words_max"
              ><template slot="append">专家</template></el-input
            >
          </el-form-item>
          <el-form-item label="回答字数下限（字）" prop="c_words_min">
            <el-input maxlength="8" v-model.number="ruleForm.c_words_min"
              ><template slot="append">专家</template></el-input
            >
          </el-form-item>

          <el-form-item>
            <el-button
              type="primary"
              v-hasPermi="['base:rangeConfig:editLabel']"
              @click="submitForm('ruleForm')"
              >保存</el-button
            >
            <el-button
              v-hasPermi="['base:rangeConfig:editLabel']"
              @click="resetForm('ruleForm')"
              >重设</el-button
            >
          </el-form-item>
        </el-form>
      </div>
    </NewCard>
  </div>
</template>
<script>
import {
  getlabelRangeConfigApi,
  getlabelRangeEditApi,
} from "@/wss/newApi_3-24/base/rangeConfig.js";
// import { getConfigEditApi } from "@/wss/newApi_3-24/base/rangeConfig.js";
import {
  getConfigListConsultApi,
  getConfigEditApi,
} from "@/wss/newApi_3-24/base/config.js";
import NewCard from "../../../components/newCard.vue";

export default {
  components: { NewCard },
  data() {
    return {
      readerData: [],
      ruleForm: {
        c_words_min: "", //回答字数下线
        c_words_max: "", //回答字数上线
        c_file_size: "", //附件数量
        c_file_num: "", //附件大小
        consult_problem_effectiveTime: "", //问题有效时间
        consult_expert_skilledMin: "", //专家擅长下限
        consult_expert_skilledMax: "", //专家擅长上限
        c_effective_hour: "", //总时长
        validTime: "",
      },

      rules: {
        c_words_min: [
          {
            required: true,
            message: "不可以为空",
            trigger: "blur",
          },
        ],
        c_words_max: [
          {
            required: true,
            message: "不可以为空",
            trigger: "blur",
          },
        ],
        c_file_size: [
          {
            required: true,
            message: "不可以为空",
            trigger: "blur",
          },
        ],
        c_file_num: [
          {
            required: true,
            message: "不可以为空",
            trigger: "blur",
          },
        ],
        consult_problem_effectiveTime: [
          {
            required: true,
            message: "不可以为空",
            trigger: "blur",
          },
        ],
        c_effective_hour: [
          {
            required: true,
            message: "不可以为空",
            trigger: "blur",
          },
        ],
        consult_expert_skilledMax: [
          {
            required: true,
            message: "不可以为空",
            trigger: "blur",
          },
        ],
        consult_expert_skilledMin: [
          {
            required: true,
            message: "不可以为空",
            trigger: "blur",
          },
        ],
      },
    };
  },
  mounted() {
    this.getRangeConfigListConsultFn();
  },
  methods: {
    async getRangeConfigListConsultFn() {
      let { code, data } = await getConfigListConsultApi();
      if (code != 200) return;
      let readerData = JSON.parse(JSON.stringify(data)),
        form = this.ruleForm;

      readerData.forEach((item) => (form[item.type] = item.value));
      this.readerData = readerData;
    },
    // 获取list
    async getlabelListLabelFn() {
      return;
      let { rows, code } = await getlabelRangeConfigApi();
      if (code != 200) return;
      let myRows = JSON.parse(JSON.stringify(rows));
      myRows.forEach((item) => {
        if (item.type == "label_user") {
          this.userlabelObj = item;
          this.ruleForm.userMax = item.max;
          this.ruleForm.userMin = item.min;
        } else if (item.type == "label_expert") {
          this.ruleForm.expertMax = item.max;
          this.ruleForm.expertMin = item.min;
        }
      });
      this.paramsLabel = myRows;
    },
    async submitForm(attr) {
      // await this.$refs[attr].validate();
      let readerData = this.readerData;
      let form = this.ruleForm;
      readerData.forEach((item) => (item.value = form[item.type]));
      let { code, msg } = await getConfigEditApi(readerData);
      if (code != 200) return;
      this.$message({
        type: "success",
        message: msg,
      });
    },
    resetForm(formName) {
      this.ruleForm = {
        userMax: "",
        userMin: "",
        expertMax: "",
        expertMin: "",
      };
      this.$refs[formName].resetFields();
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style lang="scss" scoped>
.labelSettings {
  padding-top: 20px;
  background-color: #ffffff;
  .form {
    width: 800px;
  }
}
</style>